define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'inventory/kcsafe/index' + location.search,
                    table: 'wms_kc_safe_view',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'status',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                       //{field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'number', title: __('Number'), operate: 'LIKE'},
                        {field: 'specification', title: __('Specification'), operate: 'LIKE'},
                        
                        {field: 'max_num', title:__('Max_num'),operate: false},
                        {field: 'min_num', title:__('Min_num'),operate: false},
                        {field: 'safe_num', title:__('Safe_num'),operate: false},
                        {field: 'unit', title: __('Unit'), operate: false},
                        {field: 'total_quantity', title:__('Total_quantity'),operate: false},
                        {field: 'store_unit', title: __('Store_Unit'), operate: false},
                        {field: 'total_store_quantity', title:__('Total_store_quantity'),operate: false},
                        /*{field: 'status_text', title: __('Status'), searchList: status_arr, 
                        	width:120,cellStyle:function(value,row,index) {
                        		if(row.status_text=='正常'){
                        	        return {css: {"color": "black"}};
                        		}else{
                        			return {css: {"color": "red"}};
                        		}
                        	}
                        }*/
                        {field: 'status', title: __('Status'), searchList: status_arr, 
                        	formatter: Table.api.formatter.normal,sortable:true,
                        	width:120,cellStyle:function(value,row,index) {
                        		if(row.status_text=='正常'){
                        	        return {css: {"color": "black"}};
                        		}else{
                        			return {css: {"color": "red"}};
                        		}
                        	}
                        }
                        
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

            
        },
        api: {
            selectedids: function (table, current) {
                var options = table.bootstrapTable('getOptions');
                //如果有设置翻页记忆模式
                if (!current && options.maintainSelected) {
                    return options.selectedIds;
                }
                return $.map(table.bootstrapTable('getSelections'), function (row) {
                    return row;
                });
            },
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
